import { ReactNode } from 'react'
import pluginFactory from 'core/singleton'
import { Base } from 'type'


export default class ChartPlugin {
  name: string
  tags: string[]
  description: string
  exampleGallery: { url: string }[]
  chart: (transformProps: any) => ReactNode
  constructor(config: (Base & {
    chart: (transformProps: any) => ReactNode
  })) {
    this.name = config.name
    this.tags = config.tags
    this.description = config.description
    this.exampleGallery = config.exampleGallery
    this.chart = config.chart
  }

  register<T>(key: string) {
    pluginFactory().register(key, {
      name: this.name,
      tags: this.tags,
      description: this.description,
      exampleGallery: this.exampleGallery,
      chart: this.chart,
    })
  }

  unRegister(key: string) {
    pluginFactory().remove(key)
  }

  configure(key: string) {
    pluginFactory().register(key, {
      name: this.name,
      tags: this.tags,
      description: this.description,
      exampleGallery: this.exampleGallery,
      chart: this.chart,
    })
  }
}